package com.frejoys.common.util;

import cn.hutool.crypto.SecureUtil;

public class CacheKeyUtil {

    /**
     * 请求头签名key
     * @param sign
     * @return
     */
    public static String signCacheKey(String sign) {
        return "sign:" + sign;
    }

    /**
     * 单点登录key
     * @param userId
     * @param site
     * @return
     */
    public static String singleSignCacheKey(String userId, Integer site, Integer siteType) {
        return "singleSign:" + userId + ":" + site + ":" + siteType;
    }

    /**
     * 验证码锁
     * @param account
     * @param type
     * @return
     */
    public static String accountCodeLockCacheKey(String account, Integer type) {
        return "accountCode:lock:" + account + ":" + type;
    }

    /**
     * 验证码发送计时
     * @param account
     * @param type
     * @return
     */
    public static String accountCodeExpireCacheKey(String account, Integer type) {
        return "accountCode:expire:" + account + ":" + type;
    }

    /**
     * 验证码单日2小时发送数量限制
     * @param account
     * @param type
     * @param ymd
     * @return
     */
    public static String accountCodeHourCountCacheKey(String account, Integer type, String ymd) {
        return "accountCode:count:hour:" + account + ":" + type + ":" + ymd;
    }

    /**
     * 验证码单日发送数量限制
     * @param account
     * @param type
     * @param ymd
     * @return
     */
    public static String accountCodeDayCountCacheKey(String account, Integer type, String ymd) {
        return "accountCode:count:day:" + account + ":" + type + ":" + ymd;
    }

    /**
     * 验证码单日发送数量ip限制
     * @param ipAddr
     * @param ymd
     * @return
     */
    public static String ipCodeCountCacheKey(String ipAddr, String ymd) {
        return "ipCode:count:" + ipAddr + ":" + ymd;
    }

    /**
     * 密码错误次数限制
     * @param account
     * @param type
     * @param ymd
     * @return
     */
    public static String passwordErrorCacheKey(String account, Integer type, String ymd) {
        return "password:error:" + account + ":" + type + ":" + ymd;
    }

    /**
     * 注册锁
     * @param account
     * @param type
     * @return
     */
    public static String registerLockCacheKey(String account, Integer type) {
        return "register:lock:" + account + ":" + type;
    }

    // /**
    //  * 登录锁
    //  * @param account
    //  * @param site
    //  * @return
    //  */
    // public static String loginLockCacheKey(String account, Integer site) {
    //     return "login:lock:" + account + ":" + site;
    // }

    /**
     * 登录锁
     * @param phone
     * @param site
     * @return
     */
    public static String loginLockCacheKey(String phone, Integer site) {
        return "login:lock:" + phone + ":" + site;
    }

    /**
     * 登录密码错误次数限制
     * @param phone
     * @param ymd
     * @return
     */
    public static String loginPasswordErrorCountCacheKey(String phone, String ymd) {
        return "password:count:hour:" + phone + ":" + ymd;
    }

    /**
     * 登录锁
     * @param account
     * @param site
     * @return
     */
    public static String loginWxLockCacheKey(String account, Integer site) {
        return "login:wx:lock:" + account + ":" + site;
    }

    /**
     * refreshToken锁
     * @param refreshToken
     * @param site
     * @return
     */
    public static String refreshTokenCacheKey(String refreshToken, Integer site) {
        return "token:refresh:lock:" + refreshToken + ":" + site;
    }

    /**
     * 店铺添加锁
     * @param userId
     * @return
     */
    public static String storeAddLockCacheKey(Long userId) {
        return "store:add:" + userId;
    }

    /**
     * 商品添加锁
     * @param userId
     * @return
     */
    public static String goodsAddLockCacheKey(Long userId) {
        return "goods:add:" + userId;
    }

    /**
     * 店铺编辑锁
     * @param userId
     * @return
     */
    public static String storeEditLockCacheKey(Long userId) {
        return "store:edit:" + userId;
    }


    /**
     * 店铺、商品、活动上、下架锁
     * @param userId
     * @return
     */
    public static String soldOutLockCacheKey(Long userId) {
        return "sold:out:" + userId;
    }

    /**
     * 店铺商品锁
     * @param userId
     * @return
     */
    public static String storeGoodsLockCacheKey(Long userId) {
        return "store:goods:" + userId;
    }

    /**
     * 编辑店铺商品锁
     * @param userId
     * @return
     */
    public static String upStoreGoodsLockCacheKey(Long userId) {
        return "upStore:goods:" + userId;
    }

    /**
     * 添加店铺活动锁
     * @param userId
     * @return
     */
    public static String storeActivityAddLockCacheKey(Long userId) {
        return "store:activity:" + userId;
    }

    /**
     * 编辑店铺支付码锁
     * @param userId
     * @return
     */
    public static String upStoreCodeLockCacheKey(Long userId) {
        return "upStore:code:" + userId;
    }

    /**
     * 添加店铺支付码锁
     * @param userId
     * @return
     */
    public static String addStoreCodeLockCacheKey(Long userId) {
        return "addStore:code:" + userId;
    }

    /**
     * 编辑店铺活动锁
     * @param userId
     * @return
     */
    public static String upStoreActivityLockCacheKey(Long userId) {
        return "upStore:activity:" + userId;
    }

    /**
     * 添加广告锁
     * @param userId
     * @return
     */
    public static String addAdLockCacheKey(Long userId) {
        return "add:ad:" + userId;
    }

    /**
     * 编辑广告锁
     * @param userId
     * @return
     */
    public static String upAdLockCacheKey(Long userId) {
        return "up:ad:" + userId;
    }

    /**
     * 添加品类锁
     * @param userId
     * @return
     */
    public static String addCategoryLockCacheKey(Long userId) {
        return "add:category:" + userId;
    }

    /**
     * 编辑品类锁
     * @param userId
     * @return
     */
    public static String upCategoryLockCacheKey(Long userId) {
        return "up:category:" + userId;
    }

    /**
     * 添加活动类型锁
     * @param userId
     * @return
     */
    public static String adActivityLockCacheKey(Long userId) {
        return "ad:activity:" + userId;
    }

    /**
     * 编辑活动类型锁
     * @param userId
     * @return
     */
    public static String upActivityLockCacheKey(Long userId) {
        return "up:activity:" + userId;
    }


    /**
     * 编辑活动排队队列锁
     * @param userId
     * @return
     */
    public static String upActivityQueueLockCacheKey(Long userId) {
        return "up:activity:queue:" + userId;
    }


    /**
     * 平台设置锁
     * @param userId
     * @return
     */
    public static String platformLockCacheKey(Long userId) {
        return "platform:" + userId;
    }


    /**
     * 添加权限组锁
     * @param userId
     * @return
     */
    public static String addAuthGroupLockCacheKey(Long userId) {
        return "add:auth:group:" + userId;
    }


    /**
     * 编辑权限组锁
     * @param userId
     * @return
     */
    public static String upAuthGroupLockCacheKey(Long userId) {
        return "up:auth:group:" + userId;
    }

    /**
     * 订单超时任务锁
     * @return
     */
    public static String taskOrderTimeoutLockCacheKey() {
        return "task:order:timeout";
    }

    /**
     * 订单支付回调锁
     * @param orderSn
     * @return
     */
    public static String orderPayNotifyLockCacheKey(String orderSn) {
        return "order:pay:notify:" + orderSn;
    }

    /**
     * 订单锁
     * @param userId
     * @return
     */
    public static String orderPayLockCacheKey(Long userId) {
        return "order:pay:" + userId;
    }

    //商家入驻锁
    public static String storeEnterLockCacheKey(Long userId) {
        return "store:enter:lock:" + userId;
    }

    //修改商家入驻锁
    public static String upStoreEnterLockCacheKey(Long userId) {
        return "upStore:enter:lock:" + userId;
    }

    //添加提现账号锁
    public static String userCashLockCacheKey(Long userId) {
        return "user:cash:lock:" + userId;
    }

    // 添加提现信息密码锁
    public static String addUserCashPasswordLockCacheKey(Long userId) {
        return "add:user:cash:password:lock:" + userId;
    }

    // 修改提现信息密码锁
    public static String upUserCashPasswordLockCacheKey(Long userId) {
        return "up:user:cash:password:lock:" + userId;
    }

    //编辑提现账号锁
    public static String upUserCashLockCacheKey(Long userId) {
        return "upUser:cash:lock:" + userId;
    }

    //管理员修改用户角色锁
    public static String upUserRoleLockCacheKey(Long userId) {
        return "upUser:role:lock:" + userId;
    }

    //支付码生成锁
    public static String storeCodeLockCacheKey(Long userId) {
        return "store:code:lock:" + userId;
    }

    /**
     * 订单退款锁
     * @param userId
     * @return
     */
    public static String orderRefundLockCacheKey(Long userId) {
        return "order:refund:" + userId;
    }

    /**
     * 订单通用锁
     * @param orderSn
     * @return
     */
    public static String orderCommonLockCacheKey(Long orderSn) {
        return "order:common:" + orderSn;
    }

    /**
     * 订单转积分锁
     * @param userId
     * @return
     */
    public static String orderScoreLockCacheKey(Long userId) {
        return "order:score:" + userId;
    }

    /**
     * 订单核销锁
     * @param id
     * @return
     */
    public static String orderVerifyLockCacheKey(Integer id) {
        return "order:verify:" + id;
    }

    /**
     * 订单退款回调锁
     * @param orderSn
     * @return
     */
    public static String orderRefundNotifyLockCacheKey(String orderSn) {
        return "order:refund:notify:" + orderSn;
    }

    /**
     * 订单未支付超时集合key
     * @return
     */
    public static String orderTimeoutSortedSet() {
        return "orderTimeoutSortedSet";
    }



    /**
     * 用户码生成锁
     * @param userId
     * @return
     */
    public static String userQrcodeLockKey(Long userId) {
        return "user:qrcode:" + userId;
    }

    /**
     * 订单码生成锁
     * @param orderSn
     * @return
     */
    public static String orderQrcodeLockKey(Long orderSn) {
        return "order:qrcode:" + orderSn;
    }

    /**
     * 商家线上支付码生成锁
     * @param storeId
     * @return
     */
    public static String storePayQrcodeLockKey(Integer storeId) {
        return "store:pay:qrcode:" + storeId;
    }

    /**
     * 订单任务核销任务锁
     * @return
     */
    public static String taskOrderVerifyLockKey() {
        return "task:order:verify";
    }

    /**
     * 支付码生成仓库锁
     * @return
     */
    public static String storeCodeDepositoryLockKey(Integer storeCodeBatchId) {
        return "store:code:depository" + storeCodeBatchId;
    }


    /**
     * 返利任务锁
     * @return
     */
    public static String taskRebateQueueLockKey() {
        return "task:rebate:queue";
    }

    /**
     * 商品变量数量修改任务锁
     * @return
     */
    public static String taskGoodsVarSoldCountLockKey() {
        return "task:goods:varSoldCount";
    }

    /**
     * 订单任务核销锁
     * @param orderId
     * @return
     */
    public static String orderTaskVerifyLockKey(Integer orderId) {
        return "order:task:verify:" + orderId;
    }

    /**
     * 用户推广生成锁
     * @param userId
     * @return
     */
    public static String userExtendLockKey(Long userId) {
        return "user:extend:" + userId;
    }

    /**
     * 找回密码锁
     * @param account
     * @param type
     * @return
     */
    public static String findPasswordLockCacheKey(String account, Integer type) {
        return "findPassword:lock:" + account + ":" + type;
    }

    /**
     * 修改密码锁
     * @param userId
     * @param type
     * @return
     */
    public static String changePasswordLockCacheKey(Long userId, Integer type) {
        return "changePassword:lock:" + userId + ":" + type;
    }

    /**
     * 文件缓存
     * @param filename
     * @param style
     * @return
     */
    public static String fileCacheKey(String filename, String style) {
        return "filename:" + SecureUtil.md5(filename + style);
    }

    /**
     * accessToken缓存
     * @param site
     * @return
     */
    public static String accessTokenCacheKey(Integer site) {
        return "accessToken:" + site;
    }

    /**
     * h5WxAccessToken 缓存
     * @return
     */
    public static String accessTokenH5CacheKey(Integer site) {
        return "h5WxAccessToken:"+site;
    }

    /**
     * 上架审核锁
     * @param id 审核记录id
     */
    public static String adminVerifyLockCacheKey(Long userId, Integer id) {
        return "adminVerify:"+userId+":" + id;
    }
    /**
     * 店铺月销量锁
     * @param storeId 店铺id
     */
    public static String storeStatisticsYearLockCacheKey(Integer storeId) {
        return "storeStatisticsYear:"+storeId;
    }

    /**
     *支付码key
     */
    public static String storeCodeBatchIdList() {
        return "storeCodeBatchIdList";
    }


    /**
     * 花卷云用户同步任务锁
     * @return
     */
    public static String taskHuajuanUserLockKey() {
        return "task:huajuan:user";
    }

    /**
     * 花卷云用户积分同步任务锁
     * @return
     */
    public static String taskHuajuanUserScoreLockKey() {
        return "task:huajuan:user:score";
    }


}
